/*
 * common.h
 * This file is part of OpenAnimator
 *
 * Copyright (C) 2008 - Abhinav Lele
 *
 * OpenAnimator is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * OpenAnimator is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with OpenAnimator; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, 
 * Boston, MA  02110-1301  USA
 */

#ifndef __OA_COMMON_H__
#define __OA_COMMON_H__

#include <fstream>
#include <iostream>
#include <string>
#include <map>
#include <vector>

#include "sdl/SDL.h"
#include "sdl/SDL_thread.h"

extern "C" {
#include "lua/lua.h"
#include "lua/lualib.h"
#include "lua/lauxlib.h"
}
using std::vector;
using std::map;
using std::string;
using std::cout;
using std::cerr;
using std::endl;
/*#include <SDL/SDL.h>
#include <SDL/SDL_thread.h>
#include "SDL_net.h"
*/


#define DEBUG
#ifdef DEBUG
	#define E(_m_) cerr << "[ERR] " << _m_ << endl;
	#define M(_m_) cout << "[INFO] " << _m_ << endl;
	#define T(_m_) cout << "[TRACE] " << _m_ << endl;

	#define ER(_m_,r) { cerr << "[ERR] " << _m_ << endl; return r; }
#else
	#define E(_m_) ;
	#define M(_m_) ;
	#define T(_m_) ;
	#define ER(_m_,r) ;
#endif


#define IS_STRING       1000
#define IS_INTNUMBER    2000
#define IS_NUMBER       3000
#define IS_TABLE        4000
#define TRUE       1
#define FALSE      0
#define ARG1_1     -1
#define ARG2_1     -2
#define ARG2_2     -1
#define ARG3_1     -3
#define ARG3_2     -2
#define ARG3_3     -1

#define CHECKISINT(luastate,index) ( lua_isnumber(luastate,index) ? ( lua_tonumber(luastate,index) == (int) lua_tonumber(luastate,index) ): 0  )
#define CHECKISTABLE(luastate,index) ( lua_istable(luastate,index) ? 1 : 0 )

#define API_ARGCHECK(type,luastate,index) (   (type == IS_STRING  ) ? lua_isstring(luastate,index) :                  \
                                              ( (type == IS_NUMBER  ) ? lua_isnumber(luastate,index) :                \
                                                ( ( type == IS_INTNUMBER ) ? ( CHECKISINT(luastate,index)  ) :        \
                                                  ( ( type == IS_TABLE )     ? ( CHECKISTABLE(luastate,index) ) : 0 )     \
                                                )   \
                                              )                                                                       \
                                          )




#ifdef __WIN32__
	#define OSSEP "\\"
#else
	#define OSSEP "/"
#endif

struct ltstr_stl { bool operator() ( string  s1, string  s2)    const { return s1.compare(s2)< 0;  } };


#endif
